"General
"history vim remember
set history=500
set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc,.png,.jpg
set wildignore+=*.o,*~,*.pyc,*/.git/*,*/.svn/*
"no annoying sound on errors
set noerrorbells
set novisualbell
set t_vb=
"key code delay
set timeout timeoutlen=3000 ttimeoutlen=100
"set standard encoding
set encoding=utf8
"set default <EOL> style
set fileformats=unix,dos,mac

" Colors
syntax enable
"set colorscheme
try
    set t_Co=256
	colorscheme molokai
catch
endtry

"Space&Tabs
"show 4 spaces when read a <TAB> while open a file
set tabstop=4
set shiftwidth=4
"4 spaces inserted or removed when editing
set softtabstop=4
"make <TAB> = insert 4 spaces
set expandtab

" UI Config
"show line number
set number
"show last command entered in right bottom
set showcmd
"show statusline when win > 1
set laststatus=1
"highlight the line cursor on
set cursorline
"turn on filetype detect
"and load language specific indentation file
filetype indent on
"show autocompletes menu when use command such as  [:e ~/.vim<TAB>]
set wildmenu
"redraw only when we need
set lazyredraw
"highlight matching {[()]}
set showmatch
"show cursor position
set ruler
"wrap lines
set nowrap
"show space&tab chars
set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<

" Editing
set autoindent
set smartindent

" Searching
"search when input
set incsearch
"highlight matches
set hlsearch
"set lines below&above cursor
set scrolloff=7
"ignore&smart case
set ignorecase
set smartcase
set magic

" Folding
"enable folding
set foldenable
"show fold column
set foldcolumn=1
"open most folds by default
set foldlevelstart=10
"max 10 nested fold
set foldnestmax=10
"space open/close folds
nnoremap <space> za
"fold base on indent level
set foldmethod=indent

" Movement
"move vertically by visual line
nnoremap j gj
nnoremap k gk
"move to beginning/end of line
nnoremap B ^
nnoremap E $
nnoremap ^ <nop>
nnoremap $ <nop>
"highlight last inserted text
nnoremap gV `[v`]
"Smart way to move between windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l

" Leader Shortcut
let mapleader=","
"nnoremap <leader>u :GundoToggle<CR>
nnoremap <leader>s :source ~/.vim/vimrc<CR>
"nnoremap <leader>s :mksession<CR>
nnoremap <leader>l :set list!<CR>
"disable highlight when <leader><cr>
map <silent> <leader><cr> :nohlsearch<cr>
